package com.wms.assets;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

public class Item implements Serializable {

	/**
	 * serial ID for serialization
	 */
	private static final long serialVersionUID = -8332986118516607012L;
	
	public String name;
	public Timestamp created;
	public String status; // lost/found
	public String description;
	private String location;
	public int month = -1;
	public int day = -1;
	public int year = -1;
	private String owner; // which User (could be guest) owns this item to edit
	private Map<String, Boolean> categories;
	
	public Item(String name, Boolean c, Boolean j, Boolean t, Boolean e, Boolean a, Boolean o) {
		this.name = name;
		this.location = "";
		categories = new HashMap<String, Boolean>();
		categories.put(Categories.ACCESSORIES, j);
		categories.put(Categories.ANIMALS, a);
		categories.put(Categories.CLOTHING, c);
		categories.put(Categories.ELECTRONICS, e);
		categories.put(Categories.TOYS, t);
		categories.put(Categories.MISCELLANY, o);
		categories.put(Categories.ANY, true);
		owner = "guest";
		created = new Timestamp(System.currentTimeMillis());
	}
	
	public void setLocation(String location){
		this.location = location;
	}
	
	public String getLocation(){
		if (this.location == null) 
			return "";
		return this.location;
	}
	public void setOwner(String user){
		this.owner = user;
	}
	
	public void setCreated(Timestamp createdTime){
		created = createdTime;
	}
	
	public String getOwner(){
		return this.owner;
	}
	
	public Boolean isCategory(String name) {
		return categories.get(name);
	}
	
	public Boolean addCategory(String name) {
		return categories.put(name, true);
	}
	
	public Boolean removeCategory(String name) {
		return categories.put(name, false);
	}
	
	public String getCategoriesString(){
		String categs = "default";
		for (String categ: categories.keySet())
			if (categories.get(categ)){
				categs.concat(",");
				categs.concat(categ);
			}
		return categs;
	}
	
	public String getStatus(){
		return status;
	}
	
	public String getDescription(){
		return description;
	}
	
	public String getName(){
		return name;
	}
}
